import 'package:permission_handler/permission_handler.dart';
import 'package:url_launcher/url_launcher_string.dart';

class utilLauncher{
  //打电话
  static  Future<void> phoneCall(String number) async {
    // 1. 检查并请求权限
    final status = await Permission.phone.request();
    print(">]status.isGranted=${status.isGranted}");
    //已经获取权限
    if (status.isGranted) {
      // 2. 权限允许，拨打电话
      // final phoneUrl = 'tel:10086';
      final phoneUrl = 'tel:'+ number;
      await launchUrlString(phoneUrl);

    } else if (status.isDenied) {
      print(">]用户拒绝了电话权限");
    } else if (status.isPermanentlyDenied) {
      // 3. 永久拒绝权限，提示用户去设置
      print(">]电话权限永久被拒绝，请手动开启");
      await openAppSettings(); // 打开设置页
    }
  }
  /// 发送短信（打开系统短信应用）
  static Future<void> sendSMS(String phoneNumber,String  message) async {
    try {
      final uri = 'sms:'+phoneNumber+'?body='+message;
      await launchUrlString(uri);
    } catch (e) {
      print('>]❌ 异常: $e');
    }
  }

}